package com.glut.campusrepair.controller;

import com.glut.campusrepair.entity.RepairPersonnel1;
import com.glut.campusrepair.service.IRepairPersonnel1Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 维修人员表 前端控制器
 */
@RestController
@RequestMapping("/repair-personnel1")
public class RepairPersonnel1Controller {

    @Autowired
    private IRepairPersonnel1Service repairPersonnel1Service;

    /**
     * 获取所有维修人员
     *
     * @return 维修人员列表
     */
    @GetMapping
    public ResponseEntity<List<RepairPersonnel1>> getAllRepairPersonnel() {
        try {
            List<RepairPersonnel1> personnelList = repairPersonnel1Service.list();
            if (personnelList.isEmpty()) {
                return ResponseEntity.noContent().build(); // 如果没有数据，返回 204 No Content
            }
            return ResponseEntity.ok(personnelList);
        } catch (Exception e) {
            e.printStackTrace(); // 打印异常信息
            return ResponseEntity.status(500).body(null); // 返回 500 错误
        }
    }

}
